package com.general.framework.controller;

import com.general.framework.common.Result;
import com.general.framework.entity.Menu;
import com.general.framework.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;
    @GetMapping("/list")
    public Result list() {
        List<Menu> menus = menuService.findAll();
        return Result.success(menus);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Menu menu) {
        menuService.save(menu);
        return Result.success("保存成功");
    }

    @PostMapping("/update")
    public Result update(@RequestBody Menu menu) {
        menuService.update(menu);
        return Result.success("更新成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        menuService.deleteById(id);
        return Result.success("删除成功");
    }
}